<ul class="breadcrumb">
<li><a href="#">Objectives</a></li>
  <li class="divider">/</li>
  <li><a href="<?= site_url('founder/goals/goal_details/'.$goal['objective_id'])?>"><?= $goal['obj_title']?></a></li>
  <li class="divider">/</li>
  <li class="active"><?=$goal['title']?></li>
  </ul>
  <?php if($this->session->flashdata('result_message')) {?>
<div id="alert" class="alert alert-success">
<?= $this->session->flashdata('result_message') ?>
</div>
<?php }?>
  <div class="row-fluid">
  <div class="span10">
  <header><i class="icon-pencil"></i> <?= $goal['title']?></header>
  <table width="100%" class="table-condenesed">

  <tr >
    <td colspan="2" valign="bottom">
    <small class="muted" id="completed">0% Completed</small>
    <div class="progress progress-info progress-striped">
      <div class="bar" style="width:0%"></div>
  </div></td>
 
    <td width="16%" align="right">
    <?php if(!isset($results)) {?>
    <button type="button" class="btn" id="achieved">Achieved</button>
    <?php }?>
  </td>
  <td width="9%"></td>
  </tr>
  <tr>
    <td height="37"><strong>Final Due Date :</strong>
      <?= $goal['due_date']?>
    </td>
    <td colspan="3"><strong>Assigned to</strong>
      : <?= $goal['username']?>
    </td>
    </tr>
  <tr>
    <td width="74%" height="37">&nbsp;</td>
    <td colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><strong>Goal Description</strong></td>
    <td width="1%">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4"><?= $goal['desc']?></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>

</table>
  <header>Results <span class="badge badge-info" id="results">
<?php $count = 0;
foreach($results as $result)
{
if($result->is_heading==0){
	$count = $count+1;
}
}
echo $count;
?>
</span></header>
  <?php if(count($results)==0)
  {
	echo "No Key Result has been assigned";
  } else { $i = 0;?>
   <div id="contentLeft">
<ul class="ui-sortable" style="list-style:none;margin:0;">
    <?php foreach($results as $result) {?>
      <li id="recordsArray_<?= $result->id?>" class="<?php echo ($result->is_achieved==1)? 'achieved_pattern':''?>"  >
<div class="row-fluid <?php if($result->is_heading==0){?>borders <?php }?>">

<div class="span10">

<?php if($result->is_heading==0){?>
<div class="flag_image tooltips <?php if($result->is_achieved=='0'){if(!$result->priority) { echo "none";} else {echo $result->priority;}} ?>" data-toggle="tooltip" title="Click and Drag for Reordering subtasks" data-placement="left" >

<div><?= $i=$i+1;?></div>
</div>
<?php  } else {?>
<div class="flag_image tooltips subtask_heading" data-toggle="tooltip" title="Click and Drag for Reordering subtasks" data-placement="left" >
<?= $result->desc?>&nbsp;
<span class="subtask_heading_edit">
<a href="<?=site_url('founder/goals/delete_subheading/'.$result->id.'/'.$goal['id'])?>" onclick="return confirm('Are you sure you Delete Press [Cancel] not to delete.')"><i class="icon-trash"></i></a>
</span>
</div>
<?php }?>
<input type="hidden" value="<?=$result->id?>" id="result_id<?=$result->id?>" />
<?php if($result->is_heading==0){?>
<?= $result->desc?>
<?php }?>
</div>
<div class="span1">
<?php if($result->is_heading==0){?>

<a id="<?= $result->id?>" onclick="achieve(this.id)" style="cursor:pointer" class="tooltips" data-toggle="tooltip" title="<?= $result->priority?>" data-placement="top">Pending</a></div>
<div class="span1">
<a href="<?=site_url('founder/goals/edit_result/'.$result->id)?>" title="Edit - <?= $result->desc?>" class="edit_result tooltips" data-toggle="tooltip"><i class="icon-edit"></i> </a> 

<a href="<?=site_url('founder/goals/delete_result/'.$goal['id'].'/'.$result->id)?>" data-toggle="tooltip" data-placement="right" class="tooltips" title="Delete - <?= $result->desc?>" onclick="return confirm('Are you sure you Delete Press [Cancel] not to delete.')" ><i class="icon-trash"></i></a>

</div>
</div>
</li> 
       
       <?php } }?>
    </ul> </div>
  <?php }?>

   <br />
<br />

  <header><i class="icon-comments icon-large"></i>  Add Note to this Task</header>
<div class="">
<small>You might enter a note about a call, or a meeting, or a conversation you just had with this person. Notes are great for keeping a history of your interactions or communications with someone.</small>
<br />
<br />
<label>
<textarea rows="5" cols="5" class="span12" name="note" id="note"></textarea>
<span class="text-error"><?=form_error('note')?></span>
</label>
<input type="hidden" value="<?= $goal['id']?>" name="goal_id" id="goal_id" />
<br />
<input type="button" value="Add Note" class="btn pull-right"  id="submit_note" />
</div>
<br />
<br />

<?php if($this->session->flashdata('note_message')) {?>
<div id="alert" class="alert alert-success">
<?= $this->session->flashdata('note_message') ?>
</div>
<?php }?>

<div>
<?php if(empty($notes)) {?>
<small >No Notes Till Now</small>
<?php } else {?>
<table width="100%" class="">
<?php foreach($notes as $note) {?>
  <tr>
    <td width="10%" rowspan="3" valign="top">
    <?php if(!$note->profile_image) {?>
    <img class="img-polaroid" width="48" src="<?= $this->config->base_url(); ?>assets/images/users.png" />    
	<?php } else {?>
    <img class="img-polaroid" width="48" src="<?= $this->config->base_url(); ?>assets/uploads/<?= $note->profile_image?>" />
    
	<?php }?>
    
    </td>
    <td width="90%"><strong>Note by</strong> : <?= $note->username;?>
    <?php if($note->user_id == $this->session->userdata('user_id')) {?>
    <a href="<?= site_url('founder/goals/delete_note').'/'.$note->id.'/'.$goal['id'];?>"><i class="icon-trash pull-right"></i></a>
    <?php }?>
    </td>
  </tr>
  <tr>
    <td class="muted">on <?= $note->date?></td>
  </tr>
  <tr>
    <td><?= $note->note?></td>
  </tr>
  <tr>
  <td>&nbsp;</td>
   <td>&nbsp;</td>
  
  </tr>
<?php } ?>
</table>
<?php }?>
</div>
  </div>
  <div class="span2">
  <header><i class="icon-cog"></i> Action</header>
  <ul>
  <li><a href="#myModal" role="button" data-toggle="modal">Add A New Result</a></li>
  <li><a href="<?= site_url('founder/goals/edit_goal'.'/'.$goal['id']);?>">Edit this goal</a></li>
  <li><a href="<?= site_url('founder/goals/delete_goal'.'/'.$goal['id'].'/'.$goal['objective_id'])?>">Delete this goal</a></li>
  <li><a href="#subheading" role="button" data-toggle="modal">Add New Subheading</a></li>
  
  </ul>
  </div>
  </div>
  
  
  
  <!-- Sub tasks -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <?= form_open('founder/goals/create_result/'.$goal['id'])?>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add A New Result</h3>
  </div>
  <div class="modal-body">
    <p>   
    <textarea placeholder="Add a new result" class="span12" name="result" ></textarea>    
    </p>
   <table width="100%">
   <tr>
    <td width="10%">Priority</td>
    <td width="10%">
     <label class="radio"><input type="radio" id="radioBtn4" onmouseup="toggle(this);" value="low" name="priority" /><span class="low_box"></span></label>
     </td>
     <td width="10%">
    <label class="radio"><input type="radio" id="radioBtn5" onmouseup="toggle(this);" value="medium" name="priority" /><span class="medium_box"></span></label>
    </td>    
    <td width="10%">
    <label class="radio"><input type="radio" id="radioBtn6" onmouseup="toggle(this);" value="high" name="priority" /><span class="high_box"></span></label>
    </td>
    </tr>
    </table>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-info" type="submit">Save changes</button>
    </form>
  </div>
</div>

  <!-- Sub tasks heading -->
<div id="subheading" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
 <?= form_open('founder/goals/create_result_subheading/'.$goal['id'])?>
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Add A New Result Heading</h3>
  </div>
  <div class="modal-body">
    <p>   
    <textarea placeholder="Add a new Sub Heading" class="span12" name="subheading" ></textarea>    
    </p>
   
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-info" type="submit">Save changes</button>
    </form>
  </div>
</div>

<script type="text/javascript">

$(document).ready(function(e) {
	// drag n drop	
	//alert("asd")
	jQuery(function() {
		//alert("asdds");	
		jQuery("#contentLeft ul").sortable({handle: '.flag_image', opacity: 0.6, cursor: 'move',  update: function() {			
			var order = jQuery(this).sortable("serialize") + '&action=updateRecordsListings'; 
		//	alert(order);
			jQuery.post("<?= site_url('founder/goals/result_soarting');?>", order, function(theResponse){
				//alert(theResponse);
			}); 															 
		}								  
		});
		});
		//check subtask is achieved or not 
var goal_id = $('#goal_id').val();
var results = $('#results').html();
var results_heading = <?= count($results)?> - results ;		
//alert(goal_id);
var completed_percentage =  Math.round(100 / results) ;
//alert(completed_percentage);
var completed_value = 0;
var checkcompleted = 0;
var checknotcompleted = - results_heading;
var total_results_completed = 0;
<?php foreach ($results as $res) {?>
var result_id = $('#result_id<?= $res->id?>').val()
//alert(result_id)

$.post('<?= site_url('founder/goals/check_result_is_achieved');?>',{result_id  : result_id }, function(result_msg) {
// alert(result_msg)
  if(result_msg==1)
	 {		
total_results_completed = total_results_completed + 1;	 		
completed_value = parseInt(completed_percentage) + parseInt(completed_value);	
	$('#<?= $res->id?>').html('Achieved');
		$('#<?= $res->id?>').addClass('text-success')
		$('#<?= $res->id?>').css('font-weight','bold');
		$('.bar').css('width',completed_value+'%');
		$('#completed').html(completed_value +"% Completed");	
	//alert(total_results_completed);
			//	alert(completed_value)
		$.post('<?= site_url('founder/goals/completed_percentage');?>',{comp:completed_value,id:goal_id}, function(completed) {
			//alert(completed)
			// location.reload(); 
		})
			
	 }
	 else {		 
		 checknotcompleted  = (checknotcompleted + 1);
		// alert(checknotcompleted)
		// if(checknotcompleted == subtasks)	
		//	 {
		//	$.post('<?= site_url('user/tasks/completed_percentage');?>',{comp:'0',id:task_id}, function(notcompleted) {
			
	//	}) 
		 }
});
	
<?php }?>
	
		/* end of ready function */
		});
		
			
	function achieve(str)
	{
		
		var goal_id = $('#goal_id').val();
		var result_id = str;
		var result = $('#results').html();
		//alert(result_id)
		var completed_percentage =  parseInt(100 / result) ;
		//alert(result);
		var id = "#"+str;
		if($(id).html() =='Achieved'){
		$.post('<?= site_url('founder/goals/result_unachieved');?>',{result_id : result_id }, function(data) {		
			alert(data)
				location.reload();
});	
	}
	else {
$.post('<?= site_url('founder/goals/result_achieved');?>',{result_id : result_id }, function(data) {		
			alert(data)
			location.reload();
});
	}
		}
		
		
		// subtasks edit scripts
				
$('.edit_result').click(function(event) {
	//alert('edit_result');	
  event.preventDefault();
  $.get(this.href, function(html) {
  $(html).appendTo('body').modal(); 
  });
});
	
	
// radio button 
function toggle(radioBtn)
 {   
   if(radioBtn.checked)
   {
     setTimeout("disableRadio('"+radioBtn.id+"')",10);
   } else {
     radioBtn.checked = true;
   }
 }

function disableRadio(radioId) {
    el = window.document.getElementById(radioId);
    el.checked = false;
}

// add note function
	$('#submit_note').click(function () {	
	if(!$('#note').val())
	{
	alert('Note Field is Required');	
	}
	else {			
	var notes = $('#note').val();
	var goalid = $('#goal_id').val();	
	//alert(goalid);
	jQuery.post('<?= site_url('founder/goals/add_note');?>',{note : notes , goal_id : goalid }, function(data) {
	//alert(data)
 $('#note').val("");
	  location.reload(); 
	 });
	}
	
	})	
		</script>